﻿using System; 
using System.Collections.Generic;
using System.Linq;
using UnityEngine; 

namespace XFGameFramework
{

    // 事件委托(无参)
    public delegate void XFEvent();
    // 事件委托(1参)
    public delegate void XFEvent<T1>(T1 p1);
    // 事件委托(2参)
    public delegate void XFEvent<T1, T2>(T1 p1, T2 p2);
    // 事件委托(3参)
    public delegate void XFEvent<T1, T2, T3>(T1 p1, T2 p2, T3 p3);
    // 事件委托(4参)
    public delegate void XFEvent<T1, T2, T3, T4>(T1 p1, T2 p2, T3 p3, T4 p4);
    // 事件委托(5参)
    public delegate void XFEvent<T1, T2, T3, T4, T5>(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5);
    // 事件委托(6参)
    public delegate void XFEvent<T1, T2, T3, T4, T5, T6>(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6);
    // 事件委托(7参)
    public delegate void XFEvent<T1, T2, T3, T4, T5, T6, T7>(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7);


    public class EventManager
    {

        private static Dictionary<int, Action<object[]>> events = new Dictionary<int, Action<object[]>>();

        private static Dictionary<string, int> string_hashs = new Dictionary<string, int>();
        private static Dictionary<int, string> hash_strings = new Dictionary<int, string>();

        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
        static void Init()
        {
            events.Clear();
            string_hashs.Clear();
            hash_strings.Clear();

            _events.Clear();
        }

        /// <summary>
        /// 触发事件
        /// </summary>
        /// <param name="event_name_hash">事件名称</param>
        /// <param name="args">参数</param>
        [Obsolete("已过时,请使用同名的泛型方法代替!",true)]
        public static void TriggerEvent(int event_name_hash, params object[] args)
        {
            if (!events.ContainsKey(event_name_hash)) return;
            events[event_name_hash]?.Invoke(args);
        }
        [Obsolete("已过时,请使用同名的泛型方法代替!",true)]
        public static void TriggerEvent(string event_name, params object[] args)
        { 
        }

        /// <summary>
        /// 注册事件
        /// </summary>
        /// <param name="event_name_hash">事件名称</param>
        /// <param name="callback">回调</param>
        [Obsolete("已过时,请使用同名的泛型方法代替!",true)]
        public static void AddEvent(int event_name_hash, Action<object[]> callback)
        {

            if (events.ContainsKey(event_name_hash))
            {
                events[event_name_hash] += callback;
            }
            else
            {
                Action<object[]> action = null;
                action += callback;
                events.Add(event_name_hash, action);
            }

        }

        /// <summary>
        /// 移除事件
        /// </summary>
        /// <param name="event_name_hash">事件名称</param>
        /// <param name="callback">回调</param>
        [Obsolete("已过时,请使用同名的泛型方法代替!",true)]
        public static void RemoveEvent(int event_name_hash, Action<object[]> callback)
        {

            if (!events.ContainsKey(event_name_hash))
                return;

            events[event_name_hash] -= callback;

            if (events[event_name_hash] == null)
                events.Remove(event_name_hash);

        }
        [Obsolete("已过时,请使用同名的泛型方法代替!", true)]
        public static void AddEvent(string event_name, Action<object[]> callback) {
            AddEvent(StringToHash(event_name), callback);
        }
        [Obsolete("已过时,请使用同名的泛型方法代替!",true)]
        public static void RemoveEvent(string event_name, Action<object[]> callback) {
            RemoveEvent(StringToHash(event_name), callback);
        }
 
        public static int StringToHash(string event_name)
        {
            if (string_hashs.ContainsKey(event_name))
                return string_hashs[event_name];

            int hash = Animator.StringToHash(event_name);

            string_hashs.Add(event_name, hash);
            if (!hash_strings.ContainsKey(hash))
                hash_strings.Add(hash, event_name);

            return string_hashs[event_name];
        }

        internal static string HashToString(int hash)
        {
            if (hash_strings.ContainsKey(hash))
                return hash_strings[hash];

            return string.Empty;
        }



        #region 事件系统
         
        private static Dictionary<int, Delegate> _events = new Dictionary<int, Delegate>();


        public static void AddEvent(int event_name_hash, XFEvent callback) 
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                _events.Add(event_name_hash, null);

            XFEvent e = _events[event_name_hash] as XFEvent;

            if (e == null && _events[event_name_hash] != null) 
            {
                throw new Exception(string.Format("注册事件:{0} 类型:{1} {2} 不一致,同一个事件的回调方法类型必须保持一致!",HashToString(event_name_hash), callback.GetType().FullName, _events[event_name_hash].GetType().FullName));    
            }

            _events[event_name_hash] = e + callback;
        }

        public static void RemoveEvent(int event_name_hash, XFEvent callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent e = _events[event_name_hash] as XFEvent;

            if (e == null && _events[event_name_hash] != null) 
                throw new Exception(string.Format("移除事件:{0} 类型:{1} {2}不匹配!",HashToString(event_name_hash),typeof(XFEvent).FullName, _events[event_name_hash].GetType().FullName));
            

            _events[event_name_hash] = e - callback;

            if (_events[event_name_hash] == null) 
                _events.Remove(event_name_hash); 
            
        }

        public static void TriggerEvent(int event_name_hash )
        {
            if (!_events.ContainsKey(event_name_hash)) 
                return;
             
            XFEvent d = _events[event_name_hash] as XFEvent;
            d?.Invoke();

            if (d == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("触发事件:{0} 注册的回调类型 :{1} 和 触发的回调类型:{2}不一致!",HashToString(event_name_hash), _events[event_name_hash].GetType().FullName,typeof(XFEvent).FullName));
        }


        public static void AddEvent<T1>(int event_name_hash, XFEvent<T1> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                _events.Add(event_name_hash, null);

            XFEvent<T1> e = _events[event_name_hash] as XFEvent<T1>;

            if (e == null && _events[event_name_hash] != null)
            {
                throw new Exception(string.Format("注册事件:{0} 类型:{1} {2} 不一致,同一个事件的回调方法类型必须保持一致!", HashToString(event_name_hash), callback.GetType().FullName, _events[event_name_hash].GetType().FullName));
            }

            _events[event_name_hash] = e + callback;
        }

        public static void RemoveEvent<T1>(int event_name_hash, XFEvent<T1> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1> e = _events[event_name_hash] as XFEvent<T1>;

            if (e == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("移除事件:{0} 类型:{1} {2}不匹配!", HashToString(event_name_hash), typeof(XFEvent<T1>).FullName, _events[event_name_hash].GetType().FullName));


            _events[event_name_hash] = e - callback;

            if (_events[event_name_hash] == null)
                _events.Remove(event_name_hash);

        }

        public static void TriggerEvent<T1>(int event_name_hash,T1 p)
        { 
            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1> d = _events[event_name_hash] as XFEvent<T1>;
            d?.Invoke(p);

            if (d == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("触发事件:{0} 注册的回调类型 :{1} 和 触发的回调类型:{2}不一致!", HashToString(event_name_hash), _events[event_name_hash].GetType().FullName, typeof(XFEvent<T1>).FullName));
        }



        public static void AddEvent<T1,T2>(int event_name_hash, XFEvent<T1, T2> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                _events.Add(event_name_hash, null);

            XFEvent<T1, T2> e = _events[event_name_hash] as XFEvent<T1, T2>;

            if (e == null && _events[event_name_hash] != null)
            {
                throw new Exception(string.Format("注册事件:{0} 类型:{1} {2} 不一致,同一个事件的回调方法类型必须保持一致!", HashToString(event_name_hash), callback.GetType().FullName, _events[event_name_hash].GetType().FullName));
            }

            _events[event_name_hash] = e + callback;
        }

        public static void RemoveEvent<T1,T2>(int event_name_hash, XFEvent<T1, T2> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2> e = _events[event_name_hash] as XFEvent<T1, T2>;

            if (e == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("移除事件:{0} 类型:{1} {2}不匹配!", HashToString(event_name_hash), typeof(XFEvent<T1, T2>).FullName, _events[event_name_hash].GetType().FullName));


            _events[event_name_hash] = e - callback;

            if (_events[event_name_hash] == null)
                _events.Remove(event_name_hash);

        }

        public static void TriggerEvent<T1,T2>(int event_name_hash, T1 p,T2 p2)
        {
            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2> d = _events[event_name_hash] as XFEvent<T1,T2>;
            d?.Invoke(p,p2);

            if (d == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("触发事件:{0} 注册的回调类型 :{1} 和 触发的回调类型:{2}不一致!", HashToString(event_name_hash), _events[event_name_hash].GetType().FullName, typeof(XFEvent<T1, T2>).FullName));
        }


        public static void AddEvent<T1, T2,T3>(int event_name_hash, XFEvent<T1, T2, T3> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                _events.Add(event_name_hash, null);

            XFEvent<T1, T2, T3> e = _events[event_name_hash] as XFEvent<T1, T2, T3>;

            if (e == null && _events[event_name_hash] != null)
            {
                throw new Exception(string.Format("注册事件:{0} 类型:{1} {2} 不一致,同一个事件的回调方法类型必须保持一致!", HashToString(event_name_hash), callback.GetType().FullName, _events[event_name_hash].GetType().FullName));
            }

            _events[event_name_hash] = e + callback;
        }

        public static void RemoveEvent<T1, T2, T3>(int event_name_hash, XFEvent<T1, T2, T3> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2, T3> e = _events[event_name_hash] as XFEvent<T1, T2, T3>;

            if (e == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("移除事件:{0} 类型:{1} {2}不匹配!", HashToString(event_name_hash), typeof(XFEvent<T1, T2, T3>).FullName, _events[event_name_hash].GetType().FullName));


            _events[event_name_hash] = e - callback;

            if (_events[event_name_hash] == null)
                _events.Remove(event_name_hash);

        }

        public static void TriggerEvent<T1, T2, T3>(int event_name_hash, T1 p, T2 p2,T3 p3)
        {
            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2, T3> d = _events[event_name_hash] as XFEvent<T1, T2, T3>;
            d?.Invoke(p, p2,p3);

            if (d == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("触发事件:{0} 注册的回调类型 :{1} 和 触发的回调类型:{2}不一致!", HashToString(event_name_hash), _events[event_name_hash].GetType().FullName, typeof(XFEvent<T1, T2, T3>).FullName));
        }


        public static void AddEvent<T1, T2, T3,T4>(int event_name_hash, XFEvent<T1, T2, T3, T4> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                _events.Add(event_name_hash, null);

            XFEvent<T1, T2, T3, T4> e = _events[event_name_hash] as XFEvent<T1, T2, T3, T4>;

            if (e == null && _events[event_name_hash] != null)
            {
                throw new Exception(string.Format("注册事件:{0} 类型:{1} {2} 不一致,同一个事件的回调方法类型必须保持一致!", HashToString(event_name_hash), callback.GetType().FullName, _events[event_name_hash].GetType().FullName));
            }

            _events[event_name_hash] = e + callback;
        }

        public static void RemoveEvent<T1, T2, T3, T4>(int event_name_hash, XFEvent<T1, T2, T3, T4> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2, T3, T4> e = _events[event_name_hash] as XFEvent<T1, T2, T3, T4>;

            if (e == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("移除事件:{0} 类型:{1} {2}不匹配!", HashToString(event_name_hash), typeof(XFEvent<T1, T2, T3, T4>).FullName, _events[event_name_hash].GetType().FullName));


            _events[event_name_hash] = e - callback;

            if (_events[event_name_hash] == null)
                _events.Remove(event_name_hash);

        }

        public static void TriggerEvent<T1, T2, T3, T4>(int event_name_hash, T1 p, T2 p2, T3 p3,T4 p4)
        {
            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2, T3, T4> d = _events[event_name_hash] as XFEvent<T1, T2, T3, T4>;
            d?.Invoke(p, p2, p3,p4);

            if (d == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("触发事件:{0} 注册的回调类型 :{1} 和 触发的回调类型:{2}不一致!", HashToString(event_name_hash), _events[event_name_hash].GetType().FullName, typeof(XFEvent<T1, T2, T3, T4>).FullName));
        }



        public static void AddEvent<T1, T2, T3, T4,T5>(int event_name_hash, XFEvent<T1, T2, T3, T4, T5> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                _events.Add(event_name_hash, null);

            XFEvent<T1, T2, T3, T4, T5> e = _events[event_name_hash] as XFEvent<T1, T2, T3, T4, T5>;

            if (e == null && _events[event_name_hash] != null)
            {
                throw new Exception(string.Format("注册事件:{0} 类型:{1} {2} 不一致,同一个事件的回调方法类型必须保持一致!", HashToString(event_name_hash), callback.GetType().FullName, _events[event_name_hash].GetType().FullName));
            }

            _events[event_name_hash] = e + callback;
        }

        public static void RemoveEvent<T1, T2, T3, T4, T5>(int event_name_hash, XFEvent<T1, T2, T3, T4, T5> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2, T3, T4, T5> e = _events[event_name_hash] as XFEvent<T1, T2, T3, T4, T5>;

            if (e == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("移除事件:{0} 类型:{1} {2}不匹配!", HashToString(event_name_hash), typeof(XFEvent<T1, T2, T3, T4, T5>).FullName, _events[event_name_hash].GetType().FullName));


            _events[event_name_hash] = e - callback;

            if (_events[event_name_hash] == null)
                _events.Remove(event_name_hash);

        }

        public static void TriggerEvent<T1, T2, T3, T4, T5>(int event_name_hash, T1 p, T2 p2, T3 p3, T4 p4,T5 p5)
        {
            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2, T3, T4, T5> d = _events[event_name_hash] as XFEvent<T1, T2, T3, T4, T5>;
            d?.Invoke(p, p2, p3, p4,p5);

            if (d == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("触发事件:{0} 注册的回调类型 :{1} 和 触发的回调类型:{2}不一致!", HashToString(event_name_hash), _events[event_name_hash].GetType().FullName, typeof(XFEvent<T1, T2, T3, T4, T5>).FullName));
        }


        public static void AddEvent<T1, T2, T3, T4, T5,T6>(int event_name_hash, XFEvent<T1, T2, T3, T4, T5, T6> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                _events.Add(event_name_hash, null);

            XFEvent<T1, T2, T3, T4, T5, T6> e = _events[event_name_hash] as XFEvent<T1, T2, T3, T4, T5, T6>;

            if (e == null && _events[event_name_hash] != null)
            {
                throw new Exception(string.Format("注册事件:{0} 类型:{1} {2} 不一致,同一个事件的回调方法类型必须保持一致!", HashToString(event_name_hash), callback.GetType().FullName, _events[event_name_hash].GetType().FullName));
            }

            _events[event_name_hash] = e + callback;
        }

        public static void RemoveEvent<T1, T2, T3, T4, T5, T6>(int event_name_hash, XFEvent<T1, T2, T3, T4, T5, T6> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2, T3, T4, T5, T6> e = _events[event_name_hash] as XFEvent<T1, T2, T3, T4, T5, T6>;

            if (e == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("移除事件:{0} 类型:{1} {2}不匹配!", HashToString(event_name_hash), typeof(XFEvent<T1, T2, T3, T4, T5, T6>).FullName, _events[event_name_hash].GetType().FullName));


            _events[event_name_hash] = e - callback;

            if (_events[event_name_hash] == null)
                _events.Remove(event_name_hash);

        }

        public static void TriggerEvent<T1, T2, T3, T4, T5, T6>(int event_name_hash, T1 p, T2 p2, T3 p3, T4 p4, T5 p5,T6 p6)
        {
            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2, T3, T4, T5, T6> d = _events[event_name_hash] as XFEvent<T1, T2, T3, T4, T5, T6>;
            d?.Invoke(p, p2, p3, p4, p5,p6);

            if (d == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("触发事件:{0} 注册的回调类型 :{1} 和 触发的回调类型:{2}不一致!", HashToString(event_name_hash), _events[event_name_hash].GetType().FullName, typeof(XFEvent<T1, T2, T3, T4, T5, T6>).FullName));
        }

        public static void AddEvent<T1, T2, T3, T4, T5, T6,T7>(int event_name_hash, XFEvent<T1, T2, T3, T4, T5, T6, T7> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                _events.Add(event_name_hash, null);

            XFEvent<T1, T2, T3, T4, T5, T6, T7> e = _events[event_name_hash] as XFEvent<T1, T2, T3, T4, T5, T6, T7>;

            if (e == null && _events[event_name_hash] != null)
            {
                throw new Exception(string.Format("注册事件:{0} 类型:{1} {2} 不一致,同一个事件的回调方法类型必须保持一致!", HashToString(event_name_hash), callback.GetType().FullName, _events[event_name_hash].GetType().FullName));
            }

            _events[event_name_hash] = e + callback;
        }

        public static void RemoveEvent<T1, T2, T3, T4, T5, T6, T7>(int event_name_hash, XFEvent<T1, T2, T3, T4, T5, T6, T7> callback)
        {
            if (callback == null) return;

            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2, T3, T4, T5, T6, T7> e = _events[event_name_hash] as XFEvent<T1, T2, T3, T4, T5, T6, T7>;

            if (e == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("移除事件:{0} 类型:{1} {2}不匹配!", HashToString(event_name_hash), typeof(XFEvent<T1, T2, T3, T4, T5, T6, T7>).FullName, _events[event_name_hash].GetType().FullName));


            _events[event_name_hash] = e - callback;

            if (_events[event_name_hash] == null)
                _events.Remove(event_name_hash);

        }

        public static void TriggerEvent<T1, T2, T3, T4, T5, T6, T7>(int event_name_hash, T1 p, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6,T7 p7)
        {
            if (!_events.ContainsKey(event_name_hash))
                return;

            XFEvent<T1, T2, T3, T4, T5, T6, T7> d = _events[event_name_hash] as XFEvent<T1, T2, T3, T4, T5, T6, T7>;
            d?.Invoke(p, p2, p3, p4, p5, p6,p7);

            if (d == null && _events[event_name_hash] != null)
                throw new Exception(string.Format("触发事件:{0} 注册的回调类型 :{1} 和 触发的回调类型:{2}不一致!", HashToString(event_name_hash), _events[event_name_hash].GetType().FullName, typeof(XFEvent<T1, T2, T3, T4, T5, T6, T7>).FullName));
        }
         

        public static void AddEvent(string event_name, XFEvent callback)
        {
            AddEvent(StringToHash(event_name), callback);
        }

        public static void RemoveEvent(string event_name, XFEvent callback)
        {
            RemoveEvent( StringToHash(event_name), callback);
        }

        public static void TriggerEvent(string event_name)
        {
            TriggerEvent(StringToHash(event_name));
        }


        public static void AddEvent<T1>(string event_name, XFEvent<T1> callback)
        {
            AddEvent(StringToHash(event_name),callback);
        }

        public static void RemoveEvent<T1>(string event_name, XFEvent<T1> callback)
        {
            RemoveEvent(StringToHash(event_name), callback);
        }

        public static void TriggerEvent<T1>(string event_name, T1 p)
        {
            TriggerEvent(StringToHash(event_name), p);
        }
          
        public static void AddEvent<T1, T2>(string event_name, XFEvent<T1, T2> callback)
        {
            AddEvent(StringToHash(event_name), callback);
        }

        public static void RemoveEvent<T1, T2>(string event_name, XFEvent<T1, T2> callback)
        { 
            RemoveEvent(StringToHash(event_name), callback); 
        }

        public static void TriggerEvent<T1, T2>(string event_name, T1 p, T2 p2)
        {
            TriggerEvent(StringToHash(event_name), p, p2);
        }


        public static void AddEvent<T1, T2, T3>(string event_name, XFEvent<T1, T2, T3> callback)
        {
            AddEvent(StringToHash( event_name), callback);
        }

        public static void RemoveEvent<T1, T2, T3>(string event_name, XFEvent<T1, T2, T3> callback)
        {
            RemoveEvent(StringToHash(event_name), callback);
        }

        public static void TriggerEvent<T1, T2, T3>(string event_name, T1 p, T2 p2, T3 p3)
        {
            TriggerEvent(StringToHash( event_name ), p, p2, p3);
        }


        public static void AddEvent<T1, T2, T3, T4>(string event_name, XFEvent<T1, T2, T3, T4> callback)
        {
            AddEvent(StringToHash(event_name), callback);
        }

        public static void RemoveEvent<T1, T2, T3, T4>(string event_name, XFEvent<T1, T2, T3, T4> callback)
        {
            RemoveEvent(StringToHash(event_name), callback);
        }

        public static void TriggerEvent<T1, T2, T3, T4>(string event_name, T1 p, T2 p2, T3 p3, T4 p4)
        {
            TriggerEvent(StringToHash(event_name),   p,   p2,   p3,   p4);
        }



        public static void AddEvent<T1, T2, T3, T4, T5>(string event_name, XFEvent<T1, T2, T3, T4, T5> callback)
        {
            AddEvent(StringToHash(event_name), callback);
        }

        public static void RemoveEvent<T1, T2, T3, T4, T5>(string event_name, XFEvent<T1, T2, T3, T4, T5> callback)
        {
            RemoveEvent(StringToHash(event_name), callback);
        }

        public static void TriggerEvent<T1, T2, T3, T4, T5>(string event_name, T1 p, T2 p2, T3 p3, T4 p4, T5 p5)
        {
            TriggerEvent(StringToHash(event_name), p, p2, p3, p4, p5);
        }


        public static void AddEvent<T1, T2, T3, T4, T5, T6>(string event_name, XFEvent<T1, T2, T3, T4, T5, T6> callback)
        {
            AddEvent(StringToHash(event_name), callback);
        }

        public static void RemoveEvent<T1, T2, T3, T4, T5, T6>(string event_name, XFEvent<T1, T2, T3, T4, T5, T6> callback)
        {
            RemoveEvent(StringToHash(event_name), callback);
        }

        public static void TriggerEvent<T1, T2, T3, T4, T5, T6>(string event_name, T1 p, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6)
        {
            TriggerEvent(StringToHash(event_name),p,p2,p3, p4, p5, p6);
        }

        public static void AddEvent<T1, T2, T3, T4, T5, T6, T7>(string event_name, XFEvent<T1, T2, T3, T4, T5, T6, T7> callback)
        {
            AddEvent(StringToHash(event_name),  callback);
        }

        public static void RemoveEvent<T1, T2, T3, T4, T5, T6, T7>(string event_name, XFEvent<T1, T2, T3, T4, T5, T6, T7> callback)
        {
            RemoveEvent(StringToHash(event_name), callback);
        }

        public static void TriggerEvent<T1, T2, T3, T4, T5, T6, T7>(string event_name, T1 p, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7)
        {
            TriggerEvent(StringToHash(event_name),   p,   p2,   p3,   p4,   p5,   p6,   p7);
        }


        /// <summary>
        /// 移除事件系统的所有监听
        /// </summary>
        public static void RemoveAllEvent() 
        {
            int[] keys = _events.Keys.ToArray<int>();

            foreach (var item in keys)
            {
                _events[item] = null;
            }

            _events.Clear();
        }

        /// <summary>
        /// 移除某一个事件的所有监听
        /// </summary>
        /// <param name="event_name"></param>
        public static void RemoveAllEvent(string event_name)
        {
            RemoveAllEvent(StringToHash(event_name));
        }

        public static void RemoveAllEvent(int event_name_hash) 
        {
            if (!_events.ContainsKey(event_name_hash))
                return; 
            _events[event_name_hash] = null;
            _events.Remove(event_name_hash);
        }

        #endregion 

    }

}

